<template>
  <transition name="el-zoom-in-top">
    <!-- <transition name="el-fade-in"> -->
    <el-row v-if="isVA" v-show="showed" style="margin-bottom: 20px">
      <el-col :span="23">
        <span class="bubble-va">
          {{ info.text }}
        </span>
      </el-col>
      <el-col :span="1">
        <span>
          <img class="head-img" :src="headUrl" />
        </span>
      </el-col>
    </el-row>
    <el-row v-else-if="isSelf" v-show="showed" style="margin-bottom: 20px">
      <el-col :span="23">
        <span class="bubble-self">
          {{ info.text }}
        </span>
      </el-col>
      <el-col :span="1">
        <span>
          <img class="head-img" :src="headUrl" />
        </span>
      </el-col>
    </el-row>
    <el-row v-else v-show="showed" style="margin-bottom: 20px">
      <el-col :span="1">
        <span>
          <img class="head-img" :src="headUrl" />
        </span>
      </el-col>
      <el-col :span="23">
        <span class="bubble-other">
          {{ info.text }}
        </span>
      </el-col>
    </el-row>
  </transition>
</template>

<script>
import cacheData from "../js/data";

import head1 from "../../static/heads/1.jpg";
import head2 from "../../static/heads/2.jpg";
import head3 from "../../static/heads/3.jpg";
import head4 from "../../static/heads/4.jpg";
import head5 from "../../static/heads/5.jpg";
import head6 from "../../static/heads/6.jpg";
import head7 from "../../static/heads/7.jpg";
import head8 from "../../static/heads/8.jpg";
import head9 from "../../static/heads/9.jpg";
import head10 from "../../static/heads/10.jpg";
import head11 from "../../static/heads/11.jpg";
export default {
  name: "Bubble",
  props: {
    info: Object,
  },
  data() {
    return {
      showed: false,
      headList: [
        "placeHolder",
        head1,
        head2,
        head3,
        head4,
        head5,
        head6,
        head7,
        head8,
        head9,
        head10,
        head11,
      ],
      headUrl: "",
    };
  },
  beforeMount() {
    if (this.info.senderId == cacheData?.userInfo?.uid) {
      this.headUrl = this.getHeadB64(cacheData?.userInfo?.headId);
    } else {
      for (let i = 0; i < cacheData.roomInfo.userList.length; i++) {
        let userInfo = cacheData.roomInfo.userList[i];
        if (userInfo.uid == this.info.senderId) {
          this.headUrl = this.getHeadB64(userInfo.headId);
          break;
        }
      }
    }
  },
  mounted() {
    this.showed = true;
  },
  setup() {
    return {
      getHeadB64(id) {
        return require(`../../static/heads/${id}.jpg`);
      },
    };
  },
  computed: {
    isVA() {
      return this.info.senderId === -1;
    },
    isSelf() {
      return this.info.senderId === cacheData?.userInfo?.uid;
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.bubble-va {
  position: relative;
  display: inline-block;
  max-width: calc(75%);
  min-height: 35px;
  font-size: 1em;
  padding: 6px 10px;
  text-align: left;
  word-break: break-all;
  background-color: #c0c4cc;
  color: black;
  border-radius: 12px;
  box-shadow: 0px 1px 7px -5px #000;
  border: 0px solid #000;
  margin-top: 0;
  margin-right: 10px;
}
.bubble-self {
  float: right;
  position: relative;
  display: inline-block;
  max-width: calc(75%);
  min-height: 35px;
  font-size: 1em;
  padding: 6px 10px;
  text-align: left;
  word-break: break-all;
  background-color: #62afff;
  color: black;
  border-radius: 12px;
  box-shadow: 0px 1px 7px -5px #000;
  border: 0px solid #000;
  margin-top: 0;
  margin-right: 10px;
}
.bubble-self:after {
  content: "";
  border-top: solid 5px #00800000;
  border-left: solid 10px #62afff;
  border-right: solid 10px #00800000;
  border-bottom: solid 5px #00800000;
  position: absolute;
  top: 10px;
  left: 100%;
}
.bubble-other {
  float: left;
  display: inline-block;
  line-height: 26px;
  background-color: white;
  position: relative;
  max-width: calc(75%);
  min-height: 35px;
  font-size: 1em;
  padding: 6px 10px;
  text-align: left;
  word-break: break-all;
  border-radius: 12px;
  color: #000;
  box-shadow: 0px 1px 7px -5px #000;
  border: 0px solid #000;
  margin-top: 0;
  margin-left: 45px;
}
.bubble-other:after {
  content: "";
  border-top: solid 5px #00800000;
  border-left: solid 10px #00800000;
  border-right: solid 10px white;
  border-bottom: solid 5px #00800000;
  position: absolute;
  top: 10px;
  right: 100%;
}

.head-img {
  pointer-events: none;
  user-select: none;
  border: 1px solid rgba(0, 0, 0, 0.3);
  box-shadow: 1px 1px 2px 0px rgba(0, 0, 0, 0.2);
}
</style>
